package com.may.copy.old;

import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.Socket;

/**
 * @program: com.may.netty
 * @description:
 * @author: Bobby.Ma
 * @create: 2020-09-20 10:19
 **/
public class OldIOClient {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 9999);

        FileInputStream inputStream = new FileInputStream("C:\\Users\\19167\\Desktop\\nginx-1.18.0.zip");
        DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());

        byte[] bytes = new byte[4096];
        long read;
        long total = 0;
        long start = System.currentTimeMillis();

        while ((read = inputStream.read(bytes)) != -1){
            total += read;
            dataOutputStream.write(bytes);
        }

        long end = System.currentTimeMillis();
        System.out.println("发送总字节数：" + total + "，耗时：" + (end - start) + "毫秒");

        dataOutputStream.close();
        socket.close();
        inputStream.close();
    }
}
